import { post } from '@/utils/request';
import * as api from '@/constants/api';

export default {
  namespace: 'sysSetting',

  state: {
    settingObj: {},
  },

  effects: {
    * getSysSetting({ payload }, { call, put }) {
      const res = yield call(() => post(api.SYS_SETTING_GET, payload));

      yield put({
        type: 'saveSysSetting',
        payload: res,
      });
    },
    * updateSysSetting({payload}, {call, put}){
      yield call(()=>post(api.SYS_SETTING_UPDATE, payload));

      yield put({
        type: 'saveSysSetting',
        payload,
      })
    }
  },

  reducers: {
    saveSysSetting(state, action) {
      return {
        ...state,
        settingObj: {...state.settingObj, ...action.payload},
      };
    },
  },
};
